<?php
ob_start();

    if (!session_id())
        session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <?php
            if (!isset($_SESSION['islogin']))
            {
                $_SESSION['islogin'] = 0;
            }
            
            $isLogin = $_SESSION['islogin'];
        ?>
        
        <meta charset="utf-8" />
        <title>Editor</title>

        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="css/easyui.css">
        <link rel="stylesheet" type="text/css" href="css/icon.css">
        <link rel="stylesheet" type="text/css" href="css/easyuiforms.css">

        <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>

        <script type="text/javascript">
            function loginCheck(isLogin) {
                if (isLogin==0) {
                    $('#win').window('open');
                    $('#fm').form('clear');
                    $('#win').window('refresh', '');
                } else {
                    $('#win').window('close');
                }
            }
            
            function doLogin() {
                $('#fm').form('submit',{
                    url: 'doLogin.php',
                    onSubmit: function(){
                        return $(this).form('validate');
                    },
                    success: function(result){
                        var result = eval('('+result+')');
                        
                        if (result.success){
                            
                            $.messager.show({
                                title: 'Info',
                                msg: result.msg
                            });
                            
                            location.reload();
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.msg
                            });
                            $('#fm').form('clear');
                        }
                        
                    }
                });
            }
        </script>
    </head>
    <body onload="loginCheck(<?php echo $isLogin; ?>);">
        <?php include 'header.php'; ?>

        <div id="win" 
             class="easyui-window" 
             title="Login" 
             closed="true" 
             collapsible="false"
             minimizable="false"
             maximizable="false"
             closable="false"
             resizable="false"
             style="width:300px;height:180px;">  
            
            <form id="fm" style="padding:10px 20px 10px 40px;">
                <table border="0" width="100%" cellspacing="4" cellpadding="4">
                    <tr>
                        <td style="border: none;">Username</td>
                        <td style="border: none;">
                            <input type="text" name="txtusername">
                        </td>
                    </tr>
                    <tr>
                        <td style="border: none;">Password</td>
                        <td style="border: none;">
                            <input type="password" name="txtpassword">
                        </td>
                    </tr>                    
                </table>
                <div style="padding:5px;text-align:center;">  
                    <a href="#" 
                       class="easyui-linkbutton" 
                       icon="icon-ok"
                       onclick="doLogin();">Ok</a>  
                    <a href="#" 
                       class="easyui-linkbutton" 
                       icon="icon-cancel">Cancel</a>  
                </div>  
            </form>  
        </div>  

		<?php ob_end_flush(); ?>
    </body>
</html>